package de.kardass.jsmatep.in.validation;

import de.kardass.jsmatep.in.ConfigUtil;
import de.kardass.jsmatep.schema.jSmaTePImportConfig.FieldType;
import de.kardass.jsmatep.schema.jSmaTePImportConfig.RecordImportConfigType;

public class ConfigValidator {

	public static final void validateConfig(RecordImportConfigType importConfig) {
		final FieldType[] fieldTypes = importConfig.getFields().getFieldArray();
		String fieldName;
		for (FieldType aFieldConfig : fieldTypes) {
			fieldName = ConfigUtil.getFieldName(aFieldConfig);
			
			// check wether max. just on sub property is used
			if (fieldName.indexOf('.', 0) != fieldName.lastIndexOf('.')) {
				throw new IllegalArgumentException(
						"Max just one sub-property supported, e.g. valueObject.primaryKey!\n"
						+ "Current property name [" + fieldName + "] for config: " + aFieldConfig
						+ "\n Complete XML configuration:\n" + importConfig);
			}
		}
	}

}
